<?php
    /* 发表心得体会页面后台处理
     * @param message 传递错误信息
     *  */
    header("Content-type:text/html;charset=utf-8");
    require '../inc/review.php';
    require_once '../inc/user.php';
    $message="";
    
    if (isset($_SESSION["CURRENT_USER"])) {
        $current_user=$_SESSION["CURRENT_USER"];
        $uId=$current_user["uId"];
        $bookId=$_POST["bookId"];
        if (isset($_POST["detail"]))
        {
               
               $content=$_POST["detail"];//内容
               
               if (isset($_POST["label"])) 
               { //标签
                   $labelId=$_POST["label"];
               }
               else 
               {
                   $labelId='1';
               }
               
               if(isset($_POST["reviewId"]))
               {
                   $reviewId=$_POST["reviewId"];
                   $result=updateReview($reviewId, $content, $labelId);
                   
                   echo "<script language='JavaScript'>;alert('更新书评成功');window.location.href='../style/review.php?reviewId=$reviewId';</script>";
                   return; 
               }
               else
               {
                   $title=$_POST["title"];//标题
                   //书本号
                   $result=addReview($title,$content,$bookId, $uId,$labelId); 
                   $money=updateMoney($uId);
                   if ($result>0) {
                       
                       echo "<script language='JavaScript'>;alert('发表书评成功啦，亲亲。富裕的我，已赠送给你5个金币');window.location.href='../style/book.php?bookId=$bookId';</script>";
                       return;
                   }
                   else
                   {
                       $message="发布失败，具体原因我也不懂，请联系工作人员";
                   }
               }
               
              
               
         
            
        }else 
        {
            $message="内容不能为空";
        }
        
    }else {
        $message="用户未登录，请登录后在发布帖子";
    }
        header("location:../style/errorNew.php?message=$message");
    
    
?>